package kgc.qy.controller;


import kgc.qy.pojo.Room;
import kgc.qy.service.IRoomService;
import kgc.qy.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping(value = "clinic")
@RestController
public class ClinicController {

    @Autowired
    private IRoomService roomService;

    @PostMapping(value = "showclinic")
    public CommonResult showClinic(@RequestParam(value = "name",required = false,defaultValue = "")String name,
                                   @RequestParam(value = "dn",required = false,defaultValue = "")String dn,
                                   @RequestParam(value = "status",required = false,defaultValue = "")Integer statusId
                                   ){
        List<Room> rooms = roomService.selectByName(name,dn,statusId);
        System.out.println(rooms);
        return new CommonResult(200,"",rooms);
    }

    @PostMapping(value = "insertRoom")
    public CommonResult insertRoom(@RequestParam(value = "rm",required = false,defaultValue = "")String rm,
                                   @RequestParam(value = "rmName",required = false,defaultValue = "")String rmName){
        Room room = new Room();
        room.setName(rmName);
        switch (rm){
            case "门诊内科":
                room.setDepartmentId(1l);
                break;
            case "门诊外科":
                room.setDepartmentId(2l);
                break;
            case "门诊儿科":
                room.setDepartmentId(3l);
                break;
            case "门诊眼科":
                room.setDepartmentId(4l);
                break;
            case "门诊口腔科":
                room.setDepartmentId(5l);
                break;
        }
        int i = roomService.insertRoom(room);
        return new CommonResult(200,"",i);
    }


    @PostMapping(value = "deleteRoom")
    public CommonResult deleteRoom(@RequestParam(value = "name",required = false,defaultValue = "")String name){
        System.out.println(name);
        int i = roomService.deleteRoom(name);
        return new CommonResult(200,"",i);
    }
}
